package com.vhall.component.service.export.manager;

import com.vhall.component.framework.common.exception.BusinessException;
import com.vhall.component.plugin.common.exception.BizErrorCode;
import com.vhall.component.plugin.common.utils.JsonUtil;
import com.vhall.component.service.export.common.ExportType;
import com.vhall.component.service.export.common.ExportTypeRef;

import java.util.Arrays;

/**
 * 导出业务类型管理
 *
 * @author yuanzh
 */
public class ExportTypeManager {

    /**
     * 房间列表导出标题
     */
    private static final String ROOM_LIST_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("直播ID", "直播标题", "观看限制", "一级频道", "二级频道", "直播模式", "直播创建时间", "预计开播时间"
                    , "观看总UV", "观看总PV", "APP观看总PV", "H5观看总PV", "直播中观看总UV", "直播中观看总PV", "直播中APP观看PV", "直播中H5观看PV"
                    , "最高并发", "聊天数量（条）", "直播时长", "平均观看时长（直播中）", "平均观看时长（直播回放）"));

    /**
     * 短视频房间列表导出标题
     */
    private static final String ROOM_ON_DEMAND_LIST_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("短视频ID", "短视频标题", "创建时间", "上架时间", "上下架状态", "视频时长", "创建人", "所属频道",
                    "观看总PV", "观看总UV", "APP端PV", "H5端PV",
                    "平均观看时长（秒）", "点赞", "转发", "是否关联挂件", "点击人数", "点击次数"));


    /**
     * 文档列表导出标题
     */
    private static final String DOCUMENT_LIST_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("文档ID", "文档名称", "上传人", "上传时间", "页数", "转码状态"));

    /**
     * 问卷列表导出标题
     */
    private static final String QUESTION_LIST_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("问卷ID", "问卷名称", "创建人", "创建时间", "更新时间"));

    /**
     * 用户列表导出标题
     */
    private static final String USER_LIST_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("ID", "账号", "昵称", "手机号", "加入时间", "状态"));

    /**
     * 主持人列表导出标题
     */
    private static final String ANCHOR_LIST_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("ID", "账号", "昵称", "手机号", "加入时间", "状态"));

    /**
     * 管理员列表导出标题
     */
    private static final String ADMIN_LIST_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("管理员ID", "登录名", "手机号", "邮箱", "角色", "加入时间", "状态"));

    private static final String ROOM_GOODS_EXPORT_TITLE = JsonUtil
            .toJsonString(Arrays.asList("产品代码", "产品名称", "推屏次数", "推屏时长（秒）", "点击次数", "点击人数"));
    private ExportTypeManager() {
    }

    /**
     * 根据业务类型返回对应导出关联信息
     *
     * @param type 业务类型
     * @return 导出关联信息
     * @throws BusinessException 类型不支持
     */
    public static ExportTypeRef getTypeRef(int type) throws BusinessException {
        if (ExportType.ROOM_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(ROOM_LIST_EXPORT_TITLE).export("admin-room")
                    .callback("roomService:adminExport").build();
        }
        if (ExportType.ON_DEMAND_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(ROOM_ON_DEMAND_LIST_EXPORT_TITLE).export("admin-room")
                    .callback("roomService:adminExportOnDemand").build();
        }
        if (ExportType.DOCUMENT_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(DOCUMENT_LIST_EXPORT_TITLE).export("admin-document")
                    .callback("documentService:adminExport").build();
        }
        if (ExportType.QUESTION_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(QUESTION_LIST_EXPORT_TITLE).export("admin-question")
                    .callback("questionService:adminExport").build();
        }
        String compAccount = "admin-account";
        if (ExportType.USER_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(USER_LIST_EXPORT_TITLE).export(compAccount)
                    .callback("accountService:adminExportUser").build();
        }
        if (ExportType.ANCHOR_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(ANCHOR_LIST_EXPORT_TITLE).export(compAccount)
                    .callback("accountService:adminExportUser").build();
        }

        if (ExportType.ADMIN_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(ADMIN_LIST_EXPORT_TITLE).export(compAccount)
                    .callback("accountService:exportAdmin").build();
        }

        if (ExportType.ROOM_GOODS_LIST.getValue() == type) {
            return ExportTypeRef.builder().type(type).title(ADMIN_LIST_EXPORT_TITLE).export(compAccount)
                    .callback("roomGoodsService:export").build();
        }
        throw new BusinessException(BizErrorCode.BIZ_TYPE_NOT_ALLOWED);
    }

}
